package com.jf.cloud.service.sysmanager.common.util;

import org.springframework.util.Assert;

import java.net.URLDecoder;
import java.net.URLEncoder;

/**
 *  URL 参数转换 防止乱码
 * @author ouyang 创建时间：Feb 16, 2012 9:58:52 AM
 */
public class UrlUtil {

	/**
	 * 转码
	 * @param strMing
	 * @return
	 */
	public static String encode(String strMing) {
		String strMi = "";
		try {
			Assert.hasText(strMing, "参数不能为空");
			strMi = URLEncoder.encode(strMing, "GBK");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return strMi;
	}

	/**
	 *  解码
	 * @param strMi
	 * @return
	 */
	public static String decode(String strMi) {
		String rs = "";
		try {
			Assert.hasText(strMi, "参数不能为空");
			rs =  URLDecoder.decode(strMi, "GBK");
			Assert.isNull(rs, "解密失败！请检查参数是否正常");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return rs;
	}
	 
}
